<?php
include_once dirname(dirname(__FILE__)) . '/filtro_admin.php';
include_once dirname(dirname(__FILE__)) . '/funciones/basicas.php';
?>
<html>
<head>
<?php include_once dirname(dirname(__FILE__)) . '/header.php'; ?>
</head>
<body>
<div align="center">
<form action="listar.php" method="post">
<select name="tipo">
<option selected="selected" value="">Que desea Listar?</option>
<option value="productos">Productos</option>
<option value="clientes">Clientes</option>
<option value="proveedores">Proveedores</option>
</select>
<input type="submit" name="enviar" value="enviar">
</form>
<?php
$conexion=conectar();
if(isset($_POST['enviar']) && $_POST['tipo']=='productos' )
{
   $sql = "SELECT producto.*,proveedor.nombre as nom_p
		      FROM producto,proveedor
			  WHERE proveedor.cod_prov=producto.cod_prov
           AND producto.estado != 'b'
			  ORDER BY producto.nombre";
	$consulta = mysql_query($sql,$conexion);
	$nfilas = mysql_num_rows($consulta);
	if($nfilas > 0)
	{
		  echo "<table cellpadding=5 cellspacing=0 bgcolor=#000000>
		  <tr>
		  <td bgcolor=#000066><font color=#ffffff face=Arial, Helvetica, sans-serif>Codigo</font></td>
		  <td bgcolor=#000066><font color=#ffffff face=Arial, Helvetica, sans-serif>Nombre</font></td>
		  <td bgcolor=#000066><font color=#ffffff face=Arial, Helvetica, sans-serif>Descripcion</font></td>
		  <td bgcolor=#000066><font color=#ffffff face=Arial, Helvetica, sans-serif>Categoria</font></td>
		  <td bgcolor=#000066><font color=#ffffff face=Arial, Helvetica, sans-serif>Proveedor</font></td>
		  <td bgcolor=#000066><font color=#ffffff face=Arial, Helvetica, sans-serif>Costo</font></td>
		  <td bgcolor=#000066><font color=#ffffff face=Arial, Helvetica, sans-serif>Precio</font></td>
		  <td bgcolor=#000066><font color=#ffffff face=Arial, Helvetica, sans-serif>Unidad</font></td>
		  <td bgcolor=#000066><font color=#ffffff face=Arial, Helvetica, sans-serif>Stock</font></td>
		  </tr>";
		  for($i = 0 ; $i < $nfilas ; $i++)
		  {
		    if($i%2 == 0) $color="#CCCC99";
		    else $color="#ffffff";
			 $fila = mysql_fetch_array($consulta);
		    echo "<tr>";
		    echo "<td bgcolor=".$color.">"; 
		    print "<font color=#000000 face=Arial, Helvetica, sans-serif size=1.5>".$fila["cod_prod"]."</font>"; 
		    echo "</td>";
		    echo "<td bgcolor=".$color.">";
		    print "<font color=#000000 face=Arial, Helvetica, sans-serif size=1.5>".$fila["nombre"]."</font>";
		    echo "</td>";
		    echo "<td bgcolor=".$color.">";
		    print "<font color=#000000 face=Arial, Helvetica, sans-serif size=1.5>".$fila["descripcion"]."</font>";
		    echo "</td>";
		    echo "<td bgcolor=".$color.">";
		    print "<font color=#000000 face=Arial, Helvetica, sans-serif size=1.5>".$fila["categoria"]."</font>";
		    echo "</td>";
		    echo "<td bgcolor=".$color.">";
		    print "<font color=#000000 face=Arial, Helvetica, sans-serif size=1.5>".$fila["nom_p"]."</font>";
		    echo "</td>";
		    echo "<td bgcolor=".$color.">";
		    echo "<font color=#000000 face=Arial, Helvetica, sans-serif size=1.5>$".number_format($fila['costo'],0,",",".")."</font>";
		    echo "</td>";
		    echo "<td bgcolor=".$color.">";
		    echo "<font color=#000000 face=Arial, Helvetica, sans-serif size=1.5>$".number_format($fila['precio'],0,",",".")."</font>";
		    echo "</td>";
		    echo "<td bgcolor=".$color.">";
		    print "<font color=#000000 face=Arial, Helvetica, sans-serif size=1.5>".$fila["unidad"]."</font>";
		    echo "</td>";
		    echo "<td bgcolor=".$color.">";
		    print "<font color=#000000 face=Arial, Helvetica, sans-serif size=1.5>".$fila["cantidad"]."</font>";
		    echo "</td>";
		    echo "</tr>";
		}
      $sql = urlencode($sql);
      ?>
		</table>
		<br>
      <a href="<?php echo $_SESSION['BASE'] . '/funciones/excel.php?sql=' . $sql ?>">
      <img src="<?php echo $_SESSION['BASE'] . '/img/excel.png' ?>" title="Exportar a excel" border="0">
      </a>
      <?php
	 }
}
else if(isset($_POST['enviar']) && $_POST['tipo']=='clientes')
{
	$sql="SELECT * FROM cliente WHERE estado != 'b' ORDER BY nombre";
	$consulta = mysql_query($sql)or die(mysql_error());
	$nfilas = mysql_num_rows($consulta);
	if($nfilas > 0)
	{
		echo "<table cellpadding=5 cellspacing=0 bgcolor=#000000>
		<tr>
		<td bgcolor=#000066><font color=#ffffff face=Arial, Helvetica, sans-serif>Codigo</font></td>
		<td bgcolor=#000066><font color=#ffffff face=Arial, Helvetica, sans-serif>Nombre</font></td>
		<td bgcolor=#000066><font color=#ffffff face=Arial, Helvetica, sans-serif>Rut</font></td>
		<td bgcolor=#000066><font color=#ffffff face=Arial, Helvetica, sans-serif>Giro</font></td>
		<td bgcolor=#000066><font color=#ffffff face=Arial, Helvetica, sans-serif>Direccion</font></td>
		<td bgcolor=#000066><font color=#ffffff face=Arial, Helvetica, sans-serif>Comuna</font></td>
		<td bgcolor=#000066><font color=#ffffff face=Arial, Helvetica, sans-serif>Contacto</font></td>
		<td bgcolor=#000066><font color=#ffffff face=Arial, Helvetica, sans-serif>Email</font></td>
		<td bgcolor=#000066><font color=#ffffff face=Arial, Helvetica, sans-serif>Fono</font></td>
		<td bgcolor=#000066><font color=#ffffff face=Arial, Helvetica, sans-serif>Fax</font></td>
		</tr>";
		for($i=0;$i<$nfilas;$i++)
		{
		  if($i%2==0) $color="#CCCC99";
		  else $color="#ffffff";
		  $fila=mysql_fetch_array($consulta);
		  echo "<tr>";
		  echo "<td bgcolor=".$color.">"; 
		  print "<font color=#000000 face=Arial, Helvetica, sans-serif size=1.5>".$fila["cod_cli"]."</font>"; 
		  echo "</td>";
		  echo "<td bgcolor=".$color.">"; 
		  print "<font color=#000000 face=Arial, Helvetica, sans-serif size=1.5>".$fila["nombre"]."</font>"; 
		  echo "</td>";
		  echo "<td bgcolor=".$color.">";
		  print "<font color=#000000 face=Arial, Helvetica, sans-serif size=1.5>".$fila["rut"]."</font>";
		  echo "</td>";
	 	  echo "<td bgcolor=".$color.">";
		  print "<font color=#000000 face=Arial, Helvetica, sans-serif size=1.5>".$fila["giro"]."</font>";
		  echo "</td>";
		  echo "<td bgcolor=".$color.">";
		  print "<font color=#000000 face=Arial, Helvetica, sans-serif size=1.5>".$fila["direccion"]."</font>";
		  echo "</td>";
		  echo "<td bgcolor=".$color.">";
		  print "<font color=#000000 face=Arial, Helvetica, sans-serif size=1.5>".$fila["comuna"]."</font>";
		  echo "</td>";
		  echo "<td bgcolor=".$color.">";
		  print "<font color=#000000 face=Arial, Helvetica, sans-serif size=1.5>".$fila["contacto"]."</font>";
		  echo "</td>";
		  echo "<td bgcolor=".$color.">";
		  print "<font color=#000000 face=Arial, Helvetica, sans-serif size=1.5>".$fila["mail"]."</font>";
		  echo "</td>";
		  echo "<td bgcolor=".$color.">";
		  print "<font color=#000000 face=Arial, Helvetica, sans-serif size=1.5>".$fila["telefono"]."</font>";
		  echo "</td>";
		  echo "<td bgcolor=".$color.">";
		  print "<font color=#000000 face=Arial, Helvetica, sans-serif size=1.5>".$fila["fax"]."</font>";
		  echo "</td>";
		  echo "</tr>";
		}
		$sql = urlencode($sql);
      ?>
		</table>
		<br>
      <a href="<?php echo $_SESSION['BASE'] . '/funciones/excel.php?sql=' . $sql ?>">
      <img src="<?php echo $_SESSION['BASE'] . '/img/excel.png' ?>" title="Exportar a excel" border="0">
      </a>
      <?php
	}
}
else if(isset($_POST['enviar']) && $_POST['tipo']=='proveedores')
{
	$sql="SELECT * FROM proveedor WHERE estado != 'b' ORDER BY nombre";
	$consulta=mysql_query($sql,$conexion)or die(mysql_error());
	$nfilas=mysql_num_rows($consulta);
	if($nfilas>0)
	{
		  echo "<table cellpadding=5 cellspacing=0 bgcolor=#000000>
		  <tr>
		  <td bgcolor=#000066><font color=#ffffff face=Arial, Helvetica, sans-serif>Codigo</font></td>
		  <td bgcolor=#000066><font color=#ffffff face=Arial, Helvetica, sans-serif>Nombre</font></td>
		  <td bgcolor=#000066><font color=#ffffff face=Arial, Helvetica, sans-serif>Contacto</font></td>
		  <td bgcolor=#000066><font color=#ffffff face=Arial, Helvetica, sans-serif>Direccion</font></td>
		  <td bgcolor=#000066><font color=#ffffff face=Arial, Helvetica, sans-serif>Fono</font></td>
		  <td bgcolor=#000066><font color=#ffffff face=Arial, Helvetica, sans-serif>Fax</font></td>
		  <td bgcolor=#000066><font color=#ffffff face=Arial, Helvetica, sans-serif>Email</font></td>
		  <td bgcolor=#000066><font color=#ffffff face=Arial, Helvetica, sans-serif>Rut</font></td>
		  <td bgcolor=#000066><font color=#ffffff face=Arial, Helvetica, sans-serif>Pais</font></td>
		  </tr>";
		for($i=0;$i<$nfilas;$i++)
		{
		  if($i%2==0) $color="#CCCC99";
		  else $color="#ffffff";
		  $fila=mysql_fetch_array($consulta);
		  echo "<tr>";
		  echo "<td bgcolor=".$color.">"; 
		  print "<font color=#000000 face=Arial, Helvetica, sans-serif size=1.5>".$fila["cod_prov"]."</font>"; 
		  echo "</td>";
		  echo "<td bgcolor=".$color.">"; 
		  print "<font color=#000000 face=Arial, Helvetica, sans-serif size=1.5>".$fila["nombre"]."</font>"; 
		  echo "</td>";
		  echo "<td bgcolor=".$color.">";
		  print "<font color=#000000 face=Arial, Helvetica, sans-serif size=1.5>".$fila["contacto"]."</font>";
		  echo "</td>";
		  echo "<td bgcolor=".$color.">";
		  print "<font color=#000000 face=Arial, Helvetica, sans-serif size=1.5>".$fila["direccion"]."</font>";
		  echo "</td>";
		  echo "<td bgcolor=".$color.">";
		  print "<font color=#000000 face=Arial, Helvetica, sans-serif size=1.5>".$fila["telefono"]."</font>";
		  echo "</td>";
		  echo "<td bgcolor=".$color.">";
		  print "<font color=#000000 face=Arial, Helvetica, sans-serif size=1.5>".$fila["fax"]."</font>";
		  echo "</td>";
		  echo "<td bgcolor=".$color.">";
		  print "<font color=#000000 face=Arial, Helvetica, sans-serif size=1.5>".$fila["mail"]."</font>";
		  echo "</td>";
		  echo "<td bgcolor=".$color.">";
		  print "<font color=#000000 face=Arial, Helvetica, sans-serif size=1.5>".$fila["rut"]."</font>";
		  echo "</td>";
		  echo "<td bgcolor=".$color.">";
		  print "<font color=#000000 face=Arial, Helvetica, sans-serif size=1.5>".$fila["pais"]."</font>";
		  echo "</td>";
		  echo "</tr>";
		}
		$sql = urlencode($sql);
      ?>
		</table>
		<br>
      <a href="<?php echo $_SESSION['BASE'] . '/funciones/excel.php?sql=' . $sql ?>">
      <img src="<?php echo $_SESSION['BASE'] . '/img/excel.png' ?>" title="Exportar a excel" border="0">
      </a>
      <?php
	}
}
else if(isset($_POST['enviar']) && $_POST['tipo']=="")
{
	echo "Indique lo que desea listar";
}
mysql_close($conexion);
?>

</div>
</body>
</html>
